// TOWN SCRIPT
//    Town 0: Sage's Hut (peaceful)

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

// flags:
// 0, 0        = Sage already started first conv
// 0, 1 - 0, 7 = given experience for staff piece x
// 0, 8        = erase flag (dead)
// 0, 9        = one time lockpick check flag

begintownscript;

variables;

short choice, i, r;

body;

beginstate INIT_STATE;
	turn_off_training(TRUE);
	set_crime_tolerance(5);

	set_name(6, "The Sage");
	set_char_dialogue_pic(6, 537, 0);
break;

beginstate EXIT_STATE;
	set_flag(0, 8, 0);
break;

beginstate START_STATE;
	if ((get_flag(0, 8) == FALSE) && (get_flag(2, 0) > 0)) {
		set_flag(0, 8, TRUE);
		erase_char(6);
	}
	if (get_flag(0, 9) == FALSE) {
		set_flag(0, 9, TRUE);
		if ((has_item(174) == FALSE) && (has_item(175) == FALSE) && (has_item(176) == FALSE)) {
			put_item_on_spot(35, 27, 175);
			put_item_on_spot(35, 27, 175);
			put_item_on_spot(35, 27, 175);
		}
	}
break;

beginstate 10;
	// first piece is worth 250 xp, all others worth 125 (1000 total)
	i = 1;
	r = 250;
	while (i <= 7) {
		if ((has_special_item(i) > 0) && (get_flag(0, i) == FALSE)) {
			set_flag(0, i, TRUE);
			award_party_xp(r, 25);
		}
		i = i + 1;
		r = 125;
	}
break;

beginstate 11;
	// test node (give 1 piece of the staff at a time)
	i = 1;
	while (i <= 7) {
		if (has_special_item(i) == 0) {
			change_spec_item(i, 1);
			i = 8;
		}
		i = i + 1;
	}
break;
